/* rsscxr1.p -                                                                */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/*V8:ConvertMode=NoConvert                                                    */
/* $Revision: 1.4 $                                                           */
/*                                                                            */
/*@TO DO*/ /*INSERT DETAILED DESCRIPTION HERE, THEN DELETE THIS LINE.*/
/*                                                                            */
/* $Revision: 1.4 $   BY:hze           DATE:07/12/00  ECO: *N0DK*                 */
/* REVISION: 9.1    LAST MODIFIED: 08/12/00 BY: *N0KP* myb                    */
/* REVISION: 9.1    LAST MODIFIED: 08/21/00 BY: *N0LJ* Mark Brown             */
/*                                                                            */
/*@TO DO*/ /*INSERT PROGRAM TOKENS HERE, THEN DELETE THIS LINE.*/
/*                                                                            */

/* ========================================================================== */
/* ******************************* DEFINITIONS ****************************** */
/* ========================================================================== */

/* STANDARD INCLUDE FILES */
{mfdeclre.i}
{pxmaint.i}

/* ========================================================================== */
/* ******************************* MAIN BLOCK ******************************* */
/* ========================================================================== */

/* ========================================================================== */
/* *************************** INTERNAL PROCEDURES ************************** */
/* ========================================================================== */


/*mtt*/
/*============================================================================*/
PROCEDURE readLastScheduleDetail :
/*------------------------------------------------------------------------------
<Comment1>
rsscxr1.p
readLastScheduleDetail (
   input character pPurchaseOrderId,
   input integer pPurchaseOrderLineId,
   input date pEffDate,
   input character pReleaseId,
    Buffer pSchd_Det,
   input logical pLock,
   input logical pWait)

Parameters:
   pPurchaseOrderId -
   pPurchaseOrderLineId -
   pEffDate -
   pReleaseId -
   pSchd_Det -
   pLock -
   pWait -

Exceptions:

PreConditions:

PostConditions:

</Comment1>
<Comment2>
Notes:

</Comment2>
<Comment3>
History:

</Comment3>
------------------------------------------------------------------------------*/
   define input parameter pPurchaseOrderId as character no-undo.
   define input parameter pPurchaseOrderLineId as integer no-undo.
   define input parameter pEffDate as date no-undo.
   define input parameter pReleaseId as character no-undo.
   define  parameter buffer pSchd_Det for schd_det.
   define input parameter pLock as logical no-undo.
   define input parameter pWait as logical no-undo.

   do on error undo, return error {&GENERAL-APP-EXCEPT}:

      if pLock then do:
         if pWait then
            find last pSchd_Det
               where schd_type    = 4
               and schd_nbr       = pPurchaseOrderId
               and schd_line      = pPurchaseOrderLineId
               and schd_rlse_id   = pReleaseId
               and schd_date     <= pEffDate
            exclusive-lock no-error .
         else do :
            find last pSchd_Det
               where schd_type    = 4
               and schd_nbr       = pPurchaseOrderId
               and schd_line      = pPurchaseOrderLineId
               and schd_rlse_id   = pReleaseId
               and schd_date     <= pEffDate
            exclusive-lock no-error .
            find last pSchd_Det
               where schd_type    = 4
               and schd_nbr       = pPurchaseOrderId
               and schd_line      = pPurchaseOrderLineId
               and schd_rlse_id   = pReleaseId
               and schd_date     <= pEffDate
            exclusive-lock no-wait no-error .
            if locked pSchd_Det then
               return {&RECORD-LOCKED}.
         end.
      end.
      else
         find last pSchd_Det
            where schd_type    = 4
            and schd_nbr       = pPurchaseOrderId
            and schd_line      = pPurchaseOrderLineId
            and schd_rlse_id   = pReleaseId
            and schd_date     <= pEffDate
         no-lock no-error .
      if not available pSchd_Det then
         return {&RECORD-NOT-FOUND} .
   end.
   return {&SUCCESS-RESULT}.
END PROCEDURE.
